package stu.sup.service.impl;

import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import stu.sup.entity.Collect;
import stu.sup.mapper.CollectMapper;
import stu.sup.service.ICollectService;

import java.util.List;


/**
 * Created by HUAWEI on 2020/6/22.
 */
@Service
@Transactional
public class collectServiceImpl implements ICollectService{
    @Autowired
    CollectMapper collectMapper;
    @Override
    public boolean addcollect(Collect collect) {
        int count=collectMapper.insert(collect);
         return  count==0?false:true;
    }

    @Override
    public boolean delatecollect(Collect collect) {
        int count=collectMapper.deleteByPrimaryKey(collect.getId());
        return false;
    }


    @Override
    public List<Collect> show(Integer userId) {
        List<Collect> collects=collectMapper.selectByUserId(userId);
        return collects;
    }

    @Override
    public boolean collectFlag(Integer userId, Integer productId) {
        List<Collect> collects=collectMapper.selectByUserId(userId);
        boolean flag=false;
        if(null==collects || collects.size()==0)
            flag = false;
        else{
            for (Collect collect : collects) {
                if(collect.getProductId().equals(productId)){
                    flag = true;
                    break;
                }
            }
        }
        return flag;
    }

    @Override
    public List<Collect> findByuser(int pageNum, int pageSize, int userloginId) {
        PageHelper.startPage(pageNum, pageSize);
        return collectMapper.selectByUserId(userloginId);
    }


}
